/*------------------------------------------------------------------*/
/* --- STC MCU Limited ---------------------------------------------*/
/* --- STC10/11xx Series Programmable Clock Output Demo ------------*/
/* --- Mobile: (86)13922805190 -------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966----------------------*/
/* --- Web: www.STCMCU.com -----------------------------------------*/
/* --- Web: www.GXWMCU.com -----------------------------------------*/
/* If you want to use the program or the program referenced in the  */
/* article, please specify in which data and procedures from STC    */
/*------------------------------------------------------------------*/

#include "reg51.h"

//-----------------------------------------------

/* define constants */
#define FOSC 11059200L
//#define MODE1T                      //Timer clock mode, comment this line is 12T mode, uncomment is 1T mode

#ifdef MODE1T
#define F38_4KHz (256-FOSC/2/38400)    //38.4KHz frequency calculation method of 1T mode
#else
#define F38_4KHz (256-FOSC/2/12/38400) //38.4KHz frequency calculation method of 12T mode
#endif

/* define SFR */
sfr AUXR      = 0x8e;               //Auxiliary register
sfr WAKE_CLKO = 0x8f;               //wakeup and clock output control register
sbit T0CLKO   = P1^0;               //timer0 clock output pin

//-----------------------------------------------

/* main program */
void main()
{
#ifdef MODE1T
    AUXR = 0x80;                    //timer0 work in 1T mode
#endif
    TMOD = 0x02;                    //set timer0 as mode2 (8-bit auto-reload)
    TL0 = F38_4KHz;                 //initial timer0
    TH0 = F38_4KHz;                 //initial timer0
    TR0 = 1;                        //timer0 start running
    WAKE_CLKO = 0x01;               //enable timer0 clock output

    while (1)
	T0CLKO=~T0CLKO;                      //loop
}											 

